package com.jxauaia.contest.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jxauaia.contest.common.response.PageResult;
import com.jxauaia.contest.mapper.ContestMapper;
import com.jxauaia.contest.model.dto.CompPageQueryDTO;
import com.jxauaia.contest.model.entity.Contest;
import com.jxauaia.contest.model.vo.ContestVO;
import com.jxauaia.contest.service.ContestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContestServiceImpl implements ContestService {
    @Autowired
    private ContestMapper contestMapper;

    @Override
    public PageResult pageQuery(CompPageQueryDTO compPageQueryDTO) {
        PageHelper.startPage(compPageQueryDTO.getPage(), compPageQueryDTO.getPageSize());
        // 直接使用contestMapper.pageQuery的返回结果
        Page<ContestVO> page = contestMapper.pageQuery(compPageQueryDTO);
        return new PageResult(page.getTotal(), page.getResult());
    }
    
    @Override
    public List<Contest> findAll() {
        return contestMapper.findAll();
    }
    
    @Override
    public List<Contest> getActiveContests() {
        return contestMapper.findByStatus("active");
    }
    
    @Override
    public Contest findById(Integer id) {
        return contestMapper.findById(id);
    }
}
